
package hk.ces.oxfam.patch.xml;

import hk.ces.oxfam.patch.db.result.BeanResult;
import hk.ces.oxfam.patch.obj.Bean;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author ReutyCheng
 */
public class BeanResultXML extends SQLResultXML
{
  private BeanToXML beanToXML;

  public BeanResultXML(BeanResult beanResult, BeanToXML beanToXML)
  {
    super(beanResult);
    this.beanToXML = beanToXML;
  }

  @Override
  public String[] getHeader()
  {
    return beanToXML.columns();
  }

  @Override
  public List<Object[]> getBodyItem()
  {
    BeanResult beanResult = (BeanResult) result;
    List list = beanResult.getPackedResult();
    List<Object[]> xmlItems = new ArrayList<Object[]>(list.size());
    for (Object bean : list)
    {
      xmlItems.add(beanToXML.values((Bean) bean));
    }

    return xmlItems;
  }
}
